package com.yanqu.road.dao.impl.activity.WinterLove;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.winterLove.config.WinterLoveComb;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;


public class WinterLoveComboDaoImpl extends TempDao {
    private static String getWinterLoveCombSql = "select * from `t_s_activity_winterlove_combo` where `activityId`=? ORDER BY `cellID` ASC";
    public List<WinterLoveComb> getWinterLoveCombList(int activityId) {
        List<WinterLoveComb> list = new ArrayList<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getWinterLoveCombSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                WinterLoveComb winterLoveComb = new WinterLoveComb();
                winterLoveComb.setActivityId(rs.getInt("activityId"));
                winterLoveComb.setCellID(rs.getInt("cellID"));
                winterLoveComb.setName(rs.getString("name"));
                winterLoveComb.setType(rs.getInt("type"));
                winterLoveComb.setLevel(rs.getInt("level"));
                winterLoveComb.setRewards(rs.getString("rewards"));
                winterLoveComb.setCombination(new ArrayList<>(StringUtils.stringToIntegerList(rs.getString("combination"),";")));
                list.add(winterLoveComb);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return list;
    }

}
